package com.stars.home.adapter

import android.graphics.Color
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.home.R
import com.stars.home.activity.ReceivedDetailsActivity
import com.stars.home.databinding.ItemHomeListBinding
import com.stars.home.model.TechnicianOrder
import com.stars.home.utils.DayUtils
import com.stars.home.vmodel.HomeListVModel
import com.trailer.base.base.BAdapter
import com.trailer.base.utils.B
import com.trailer.base.utils.UiSwitch

class HomeListAdapter(var vm: HomeListVModel) :
    BAdapter<TechnicianOrder, BaseDataBindingHolder<ItemHomeListBinding>>(R.layout.item_home_list) {
    override fun convert(holder: BaseDataBindingHolder<ItemHomeListBinding>, item: TechnicianOrder) {
        holder.dataBinding?.item = item
        holder.dataBinding?.vm = vm
        holder.dataBinding?.position=holder.adapterPosition
        //设置状态
        if(item.technicianStatus==-1||item.technicianStatus==0||item.technicianStatus==5){

            if(item.technicianStatus == 0 ){
                holder.dataBinding?.tvStatus?.text="待接单"
                holder.dataBinding?.tvStatus?.setTextColor(Color.parseColor("#FFAF00"))
            }
            if( item.technicianStatus == -1){

                holder.dataBinding?.tvStatus?.text="已拒单"
                holder.dataBinding?.tvStatus?.setTextColor(Color.parseColor("#F14351"))
            }
            if( item.technicianStatus == 5){

                holder.dataBinding?.tvStatus?.text="已完成"
                holder.dataBinding?.tvStatus?.setTextColor(Color.parseColor("#08CDB2"))
            }

        }else{
            holder.dataBinding?.tvStatus?.text="进行中"
            holder.dataBinding?.tvStatus?.setTextColor(Color.parseColor("#2BA3FF"))
        }


            //设置服务列表
        var  adapter=ServerOrderAdapter()
        holder.dataBinding?.recyclerServer?.adapter=adapter
        adapter.addData(item.serviceInfo)

        adapter.setOnItemClickListener { adapter, view, position ->

            UiSwitch.bundle(
                context(),
                ReceivedDetailsActivity::class.java, B().putString("id", item.id).ok()
            )
        }


        if(null!=item.serviceTime) {
            holder.dataBinding?.tvTime?.text = DayUtils.getToday(item.serviceTime)
        }else{
            holder.dataBinding?.tvTime?.text=null
        }
        //查看详情


        holder.dataBinding?.ll?.onClick {


            UiSwitch.bundle(
                context(),
                ReceivedDetailsActivity::class.java, B().putString("id", item.id).ok()
            )

        }

        holder.dataBinding?.llDetails?.onClick {
            //查看详情

            UiSwitch.bundle(
                context(),
                ReceivedDetailsActivity::class.java, B().putString("id", item.id).ok()
            )




        }

    }
}
